﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Text;


public partial class addmanage : System.Web.UI.Page
{
	public string sss = "";
	protected void Page_Load(object sender,EventArgs e)
	{if (Session["User"]==null)
		{
			Response.Write("<script language=javascript>alert('您没有管理权限或者还没有登录，请先登录！');window.open('../login.aspx','_top');</script>");
			Response.End();
		}
		if (!IsPostBack)
        {
            showbind();
        }

	}
	public void showbind()
    {
        DataSet dst = Socut.Data.ExecuteDataSet("select * from web_notice_bigclass order by bigclassorder");
        //string str = dst.Tables[0].Rows[0]["ks"].ToString();;
        //string[] strtype=str.Split(',');
        //dst.Clear();
        //sdatype.Dispose();

        //Response.Write(strtype);

        DataSet ds = Socut.Data.ExecuteDataSet("select * from web_notice_smallclass order by smallclassorder");

        string strbigclass = "";
        string strsmallclass = "";
		
        System.Text.StringBuilder sb = new System.Text.StringBuilder();

        foreach (DataRow dr1 in dst.Tables[0].Rows)
        {
            int count = 0;
            strbigclass = dr1["id"].ToString();
            sb.Append("<table width='100%' border='0' align='center' cellpadding='0' cellspacing='1' bgcolor='#D7EBEC' class='dhlink'><tr><td colspan='6' height='30' bgcolor='#F4FCFF'><font color='#00527A'><b>" + dr1["bigclassname"] + "</font></b></td></tr><tr>");
            foreach (DataRow dr2 in ds.Tables[0].Rows)
            {
                strsmallclass = dr2["bigclassid"].ToString();
                if (check_class(strbigclass.Split(','), strsmallclass))
                {
                    count++;
                    sb.Append("<td width=15% height=20 bgcolor='#ffffff'><input id='LimitCheck' name='LimitCheck' type='checkbox' style='border:0 ' value='"+dr2["id"]+"' />" + dr2["smallclassname"] + "</td>");
                    if (count % 6 == 0)
                    {

                        sb.Append("</tr><tr>");


                    }
                }
            }
            int aa = count % 6;
            for (int i = aa; i < 6; i++)
            {
                sb.Append("<td width=15% height=20 bgcolor='#ffffff'>&nbsp;</td>");
            }
            if (sb.ToString().EndsWith("<tr>"))
            {
                sb.Remove(sb.Length - 4, 4);

            }
            if (sb.ToString().EndsWith("</td>"))
            {
                sb.Append("</tr>");
            }
            sb.Append("</table>");
        }
        sss = sb.ToString();

    }



	protected void AddBtn_Click(object sender,EventArgs e)
	{
		string Msg, Url;

			string Npwd=FormsAuthentication.HashPasswordForStoringInConfigFile(this.NewPassword.Text, "md5");
			string diction = Request.Form["LimitCheck"];
			//diction = diction.Substring(0, diction.Length - 1);

			//Response.Write(diction);
			//Response.End();
			Socut.Data.ExecuteNonQuery("insert into web_admin (LoginName,Pwd,limitcheck,truename,depart) Values ('"+LoginName.Text+"','"+Npwd+"','"+diction+"','"+truename.Text+"','"+depart.Text+"')");
			//Response.Write(LoginName.Text);
			//Response.End();
            Msg = "添加成功！";
            Url = "addmanage.aspx";
			CommonFunction.ShowMessage(Msg,Url);
         
	}

	protected void ReturnBtn_Click(object sender,EventArgs e)
	{
		Response.Redirect("Manage.aspx");
	}
	
	private bool check_class(string[] ksarry, string ksid)
    {
        for (int i = 0; i < ksarry.Length; i++)
        {
            if (ksarry[i] == ksid)
            {
                return true;
            }
        }
        return false;
    }
}
